package com.briup.web.controller;

import com.briup.pojo.User;
import com.briup.pojo.dto.UserBaseDto;
import com.briup.pojo.dto.UserPageDto;
import com.briup.pojo.vo.UserPageVO;
import com.briup.pojo.response.Result;
import com.briup.service.UserService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Api(tags = "用户管理模块接口")
@RestController
@RequestMapping("/users")
public class UserController {

	@Resource
	private UserService userService;

	@ApiOperation("分页多条件查询用户信息")
	@GetMapping
	public Result<PageInfo<UserPageVO>> list(UserPageDto userPageDto) {
		log.info("分页多条件查询用户数据:{}", userPageDto);
//		log.info("哈哈:"+userPageDto);
//		log.debug("debug test");
//		log.warn("warn test");
//		log.error("error test");
		return Result.success(userService.getUsersPageByConditional(userPageDto));
	}

	@ApiOperation("删除用户")
	@DeleteMapping("/{ids}")
	public Result<String> deleteUsers(@PathVariable("ids") List<Integer> ids) {
		log.info("删除用户:{}", ids);
		userService.deleteUsers(ids);
		System.out.println("测试删除");
		return Result.success();
	}

	@ApiOperation(value = "添加用户")
	@PostMapping
	public Result<String> addUser(@RequestBody UserBaseDto userBaseDto){
		userService.addUser(userBaseDto);
		System.out.println("添加用户测试");
		return Result.success();
	}
	@ApiOperation("获取用户信息")
	@GetMapping("/{id}")
	public Result<User> getUserInfo(@PathVariable("id") Integer
											id) {

		log.info("获取{}号用户的信息:", id);
		return Result.success(userService.getUserById(id));
	}
}
